<template>
  <div class="app-container">
    <el-table
      v-if="wdqdList.length > 0"
      :data="wdqdList"
      style="margin-bottom: 50px"
    >
      <el-table-column label="公司名称" align="center" width="270">
        <template slot-scope="scope">
          <div class="company" @click="open2 = true">
            <div class="left">
              <img
                :src="scope.row.picUrl ? baseUrl + scope.row.picUrl : c"
                :width="80"
                :height="80"
                alt="职位图片"
              />
              <div class="pro">
                {{ scope.row.combinedInfo.employmentType }}
              </div>
              <div class="id">{{ scope.row.combinedInfo.id }}</div>
            </div>
            <div class="right">
              <div class="titlename">
                {{ scope.row.combinedInfo.positionName }}
              </div>
              <div class="brand">
                {{ scope.row.combinedInfo.brandName }}
              </div>
              <div>
                <el-tag type="danger" v-if="scope.row.interviewdeadline == 'Y'"
                  >面试已截至</el-tag
                >
              </div>
              <div>
                <el-tag type="info" v-if="scope.row.isFull == 'Y'"
                  >已抢满</el-tag
                >
              </div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="负责人"
        align="center"
        prop="positionResponsiblePerson"
      />
      <el-table-column
        label="联系PM"
        align="center"
        prop="phonenumber"
        width="200"
      />
      <el-table-column label="约面" align="center">
        <template slot-scope="scope">
          {{ scope.row.aboutFaceNum || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="到面" align="center">
        <template slot-scope="scope">
          {{ scope.row.toFaceNum || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="offer" align="center">
        <template slot-scope="scope">
          {{ scope.row.offerNum || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="入职" align="center">
        <template slot-scope="scope">
          {{ scope.row.entryNum || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center">
        <el-button
          size="mini"
          type="text"
          v-hasPermi="['system:yg:add']"
          @click="handleAdd()"
          >人选录入</el-button
        >
      </el-table-column>
    </el-table>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="寻访顾问" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入寻访顾问"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工编号" prop="ygNo">
        <el-input
          v-model="queryParams.ygNo"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主状态" prop="statusOne">
        <el-select
          v-model="queryParams.statusOne"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="全部" value=""> </el-option>
          <el-option label="服务中" value="1"> </el-option>
          <el-option label="已淘汰" value="2"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="子状态" prop="statusThree">
        <el-select
          clearable
          v-model="queryParams.statusThree"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="(item, index) in childrenStatusList"
            :key="index"
            :label="item.name"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div
      style="
        display: flex;
        justify-content: space-between;
        align-items: anchor-center;
      "
    >
      <div>
        <el-radio-group
          v-model="queryParams.statusTwo"
          style="margin-bottom: 10px"
          size="mini"
          @change="listTab()"
          v-for="(item, index) in staffStatus"
          :key="index"
        >
          <el-radio-button :label="item.value"
            >{{ item.name }}({{ count[item.value] || 0 }})</el-radio-button
          >
        </el-radio-group>
      </div>
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="open4 = true"
        v-hasPermi="['system:yg:export']"
        >导出</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      :data="ygList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="员工编号" align="center" prop="ygNo" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="项目名称" align="center">
        <template slot-scope="scope">
          {{ "【" + scope.row.brandName + "】-" + scope.row.positionName }}
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="手机号" align="center" prop="tel" />
      <el-table-column label="期望城市" align="center" prop="expectationCity" />
      <el-table-column label="寻访顾问" align="center" prop="userName" />
      <el-table-column label="团队" align="center" prop="deptName" />
      <el-table-column label="人选状态" align="center" width="120">
        <template slot-scope="scope">
          <div @click="getListYgrecord(scope.row.ygId)">
            <el-link
              type="primary"
              :underline="false"
              v-if="scope.row.statusOne == '1'"
              >{{ statusTwoList[scope.row.statusTwo].StatusName }} -
              {{ statusThreeList[scope.row.statusThree] }}</el-link
            >
            <el-link type="primary" :underline="false" v-else>已淘汰</el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="最近操作时间" align="center" prop="" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="超时淘汰时间"
        align="center"
        prop="eliminationTime"
        width="180"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.statusTwo < 4 && scope.row.statusOne == '1'">{{
            scope.row.eliminationTime
          }}</span>
          <span v-else>-/-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template
          slot-scope="scope"
          v-if="scope.row.statusTwo != '7' && scope.row.statusOne != '2'"
        >
          <el-dropdown
            @command="handleCommand($event, scope.row)"
            v-if="
              scope.row.statusTwo < 3 ||
              (scope.row.statusTwo >= 3 &&
                ($store.state.user.roleId == 6 ||
                  $store.state.user.roleId == 1 ||
                  $store.state.user.roleId == 2))
            "
          >
            <span style="font-size: 20px"> ... </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="1" v-if="scope.row.statusTwo != '6'"
                >淘汰</el-dropdown-item
              >
              <el-dropdown-item command="2">编辑</el-dropdown-item>
              <el-dropdown-item
                command="3"
                v-if="
                  scope.row.statusTwo == '1' ||
                  (scope.row.statusTwo != '1' &&
                    ($store.state.user.roleId == 6 ||
                      $store.state.user.roleId == 1 ||
                      $store.state.user.roleId == 2))
                "
                >{{ operate }}</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
          <div style="margin: 10px">
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.statusTwo == '6'"
              v-hasPermi="['system:slmx:add']"
              @click="createaddSlmx(scope.row)"
              >生成工单</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="方式">
          <el-radio-group v-model="way" @change="changWay()">
            <el-radio :label="1">手动录入</el-radio>
            <el-radio :label="2">简历筛选</el-radio>
            <!-- <el-radio :label="3">批量录入</el-radio> -->
          </el-radio-group>
        </el-form-item>
        <el-form-item label="筛选人员" v-if="way != 1">
          <el-select v-model="jlId" @change="findJl()" filterable>
            <el-option
              v-for="(item, index) in jlList"
              :key="index"
              :label="item.tel + '-' + item.name"
              :value="item.jlId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input
            v-model="form.name"
            placeholder="请输入姓名"
            :disabled="way == 2"
          />
        </el-form-item>
        <el-form-item label="手机号" prop="tel">
          <el-input
            v-model="form.tel"
            placeholder="请输入手机号"
            :disabled="way == 2"
          />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex" :disabled="way == 2">
            <el-radio label="男">男</el-radio>
            <el-radio label="女">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="出生年份" prop="yearBirth">
          <el-date-picker
            :disabled="way == 2"
            v-model="form.yearBirth"
            type="year"
            value-format="yyyy"
            placeholder="选择年"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="学历" prop="educational">
          <el-select v-model="form.educational" :disabled="way == 2">
            <el-option
              v-for="(item, index) in educations.filter(
                (v) => v.name != '不限'
              )"
              :key="index"
              :label="item.name"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="期望职位" prop="expectationJop">
          <el-input
            :disabled="way == 2"
            v-model="form.expectationJop"
            placeholder="请输入期望职位"
          />
        </el-form-item>
        <el-form-item label="期望城市" prop="expectationCity">
          <el-cascader
            :disabled="way == 2"
            clearable
            filterable
            :props="{
              emitPath: false,
            }"
            :show-all-levels="false"
            v-model="form.expectationCity"
            :options="regionData"
          ></el-cascader>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer title="编辑" :visible.sync="open1" size="40%">
      <el-form
        label-width="150px"
        label-position="left"
        ref="row"
        class="demo-table-expand1"
        :model="row"
        :rules="rules1"
      >
        <el-form-item>
          <template #label><h3>基本信息</h3></template>
        </el-form-item>

        <div style="border-bottom: 1px solid #e6ebf5">
          <el-row :gutter="10" class="mb8">
            <el-col :span="12"
              ><el-form-item label="人员编号:">
                <el-input
                  v-model="row.ygNo"
                  :disabled="true"
                ></el-input> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item label="姓名:">
                <el-input
                  v-model="row.name"
                  :disabled="true"
                ></el-input></el-form-item
            ></el-col>

            <el-col :span="12"
              ><el-form-item label="创建时间:">
                <el-input
                  v-model="row.createTime"
                  :disabled="true"
                ></el-input></el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item>
                <template #label>
                  <el-tooltip class="item" effect="dark" placement="top-start">
                    <div slot="content">
                      寻访中:默认1个工作日后无操作淘汰<br />
                      约面:默认1个工作日后无操作淘汰，可修改面试时间延长淘汰时间<br />
                      到面:默认3个工作日后无操作淘汰，可修改到面时间延长淘汰时间<br />
                      offer:3个工作日后无操作自动作废，可修改预计入职时间延长作废时间，无超时淘汰<br />
                      要点:除了入职，离职外，其他均可手动淘汰
                    </div>
                    <span
                      ><i class="el-icon-warning-outline"></i>
                      超时淘汰时间:</span
                    >
                  </el-tooltip>
                </template>
                <el-input
                  v-if="row.statusTwo < 4"
                  v-model="row.eliminationTime"
                  :disabled="true"
                ></el-input>
                <span v-else>-/-</span>
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <el-form-item
          v-if="
            isTime1 ||
            isTime2 ||
            isTime3 ||
            (statusTwo == '2' && index != 3) ||
            (statusTwo == '3' && index != 3) ||
            (statusTwo == '4' && index != 3)
          "
        >
          <template #label><h3>岗位信息</h3></template>
        </el-form-item>
        <div
          style="border-bottom: 1px solid #e6ebf5"
          v-if="
            isTime1 ||
            isTime2 ||
            isTime3 ||
            (statusTwo == '2' && index != 3) ||
            (statusTwo == '3' && index != 3) ||
            (statusTwo == '4' && index != 3)
          "
        >
          <el-row :gutter="10" class="mb8">
            <el-col
              :span="12"
              v-if="isTime1 || (statusTwo == '2' && index != 3)"
              ><el-form-item label="面试时间:" prop="interviewTime">
                <!-- <el-input v-model="row.interviewTime"></el-input> -->
                <el-date-picker
                  v-model="row.interviewTime"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm"
                  format="yyyy-MM-dd HH:mm"
                  placeholder="选择日期时间"
                  :picker-options="{ disabledDate }"
                  align="right"
                >
                </el-date-picker></el-form-item
            ></el-col>

            <el-col
              :span="12"
              v-if="isTime2 || (statusTwo == '3' && index != 3)"
              ><el-form-item label="到面时间:" prop="arrivalTime">
                <el-date-picker
                  v-model="row.arrivalTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="选择日期时间"
                  align="right"
                >
                </el-date-picker> </el-form-item
            ></el-col>
            <el-col
              :span="12"
              v-if="isTime3 || (statusTwo == '4' && index != 3)"
              ><el-form-item label="预计入职时间:" prop="offerTime">
                <el-date-picker
                  v-model="row.offerTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="选择日期时间"
                  align="right"
                >
                </el-date-picker> </el-form-item
            ></el-col>
            <el-col
              :span="24"
              v-if="isTime1 || (statusTwo == '2' && index != 3)"
              ><el-form-item label="面试地点:">
                <el-input
                  type="textarea"
                  v-model="row.interviewAddress"
                  :disabled="true"
                ></el-input> </el-form-item
            ></el-col>
            <el-col :span="24" v-if="isTime1"
              ><el-form-item label="短信通知:" prop="isSend">
                <el-radio-group v-model="row.isSend">
                  <el-radio label="1">发送</el-radio>
                  <el-radio label="2">不发送</el-radio>
                </el-radio-group>
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <el-form-item v-if="index != 3">
          <template #label><h3>人选状态</h3></template>
        </el-form-item>
        <div v-if="index != 3">
          <el-form-item label="当前状态:"
            >{{ statusThreeList[statusThree] }}
          </el-form-item>
          <el-form-item label="子状态:">
            <el-radio-group v-model="row.statusThree">
              <el-radio
                v-for="(item, index) in statusList"
                :key="index"
                :label="item.value"
                >{{ item.name }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </div>
      </el-form>

      <div style="position: absolute; right: 250px; bottom: 100px">
        <el-button type="primary" @click="submitForm1()">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-drawer>
    <el-drawer
      title="职位信息"
      :visible.sync="open2"
      direction="ltr"
      width="40%"
    >
      <el-form label-position="left" class="demo-table-expand">
        <el-form-item label=""><h3>职位基本信息</h3></el-form-item>
        <div style="border-bottom: 1px solid #e6ebf5">
          <el-row :gutter="10" class="mb8">
            <el-col :span="12"
              ><el-form-item label="职位名称:">
                {{ qdkbData.positionName }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="用工类型:">
                {{ qdkbData.employmentType }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="品牌:">
                {{ qdkbData.brandName }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="需求入职:">
                {{ qdkbData.requiredQuantity }}人
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职能:">
                {{ qdkbData.fn }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="工作地点:">
                {{ qdkbData.workAdress }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <div style="border-bottom: 1px solid #e6ebf5">
          <el-row :gutter="10" class="mb8">
            <el-col :span="12"
              ><el-form-item label="年龄:">
                {{ qdkbData.ageRange || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="性别:">
                {{ qdkbData.genderRequirement || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="学历:">
                {{ qdkbData.educationRequirement || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="工作经验:">
                {{ qdkbData.experienceRequirement || "不限" }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <div>
          <el-row :gutter="10" class="mb8">
            <el-col :span="24"
              ><el-form-item label="面试地点:">
                {{ qdkbData.interviewAddress }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="面试时间:">
                {{ qdkbData.interviewStartDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="结束时间:">
                {{ qdkbData.interviewSendDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="工作时间:">
                {{ qdkbData.workDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位负责人:">
                {{ qdkbData.positionResponsiblePerson }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位负责人电话:">
                {{ qdkbData.phonenumber }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位参与人:">
                {{ qdkbData.positionParticipants }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位亮点:">
                {{ qdkbData.positionHighlights }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位描述:">
                {{ qdkbData.positionDescription }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="沟通要点:">
                {{ qdkbData.communicate }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <el-form-item label=""><h3>薪资福利</h3></el-form-item>
        <div>
          <el-row :gutter="10" class="mb8">
            <el-col :span="24"
              ><el-form-item label="基本薪资:">
                {{ qdkbData.baseSalary }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="综合薪资:">
                {{ qdkbData.totalSalary }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="其他构成:">
                {{ qdkbData.salaryComponents }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="薪资备注:">
                {{ qdkbData.salaryNotes }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="提供住宿:">
                {{ qdkbData.hasHousingProvided == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="社保:">
                {{ qdkbData.hasSocialInsurance == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="商保:">
                {{ qdkbData.hasCommercialInsurance == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="公积金:">
                {{ qdkbData.hasHousingFund == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
      </el-form>
    </el-drawer>
    <el-dialog title="操作记录" :visible.sync="open3" width="500px">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in ygrecordList"
          :key="index"
          :timestamp="item.createTime"
          placement="top"
        >
          <el-card>
            <div style="margin-bottom: 10px">
              操作人：{{ item.userName || "系统" }}
            </div>
            <el-link
              type="primary"
              :underline="false"
              v-if="item.statusOne == '2'"
              >已淘汰</el-link
            >
            <el-link type="primary" :underline="false" v-else>
              {{
                statusTwoList[item.statusTwo].StatusName +
                " - " +
                statusThreeList[item.statusThree]
              }}
            </el-link>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
    <el-dialog title="数据导出" :visible.sync="open4" width="500px">
      <div style="display: flex; justify-content: space-around">
        <el-button type="primary" plain @click="handleExport(true)"
          >导出全部</el-button
        >
        <el-button type="primary" plain @click="handleExport(false)"
          >当前tap</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYg, getYg, delYg, addYg, updateYg, listJl } from "@/api/system/yg";
import { listYgrecord } from "@/api/system/ygrecord";
import { getWdqd } from "@/api/system/wdqd";
import { addSlmx } from "@/api/system/slmx";
import c from "@/assets/c.jpg";
import {
  educations,
  staffStatus,
  statusTwoList,
  statusThreeList,
} from "@/utils/data.js"; // 根据实际路径调整
import { regionData } from "@/utils/address.js";
export default {
  name: "Yg",
  data() {
    return {
      c,
      baseUrl: process.env.VUE_APP_BASE_API,
      currentDate: new Date(),
      educations,
      staffStatus,
      statusTwoList,
      statusThreeList,
      regionData,
      childrenStatus: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      ygList: [],
      jlList: [],
      way: 1,
      jlId: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      open3: false,
      open4: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qdkbId: null,
        pmId: null,
        tlId: null,
        userId: null,
        jlId: null,
        ygNo: null,
        tel: null,
        statusOne: "1",
        statusTwo: "1",
        backStatus: null,
        backMoney: null,
        reason: null,
        withdrawalStatus: null,
        interviewTime: null,
        arrivalTime: null,
        offerTime: null,
        entryTime: null,
        resignationTime: null,
        eliminationTime: null,
        name: null,
      },
      // 表单参数
      form: {},
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        tel: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        educational: [
          { required: true, message: "学历不能为空", trigger: "blur" },
        ],
        yearBirth: [
          { required: true, message: "出生年份不能为空", trigger: "blur" },
        ],
        expectationJop: [
          { required: true, message: "期望职位不能为空", trigger: "blur" },
        ],
        expectationCity: [
          { required: true, message: "期望城市不能为空", trigger: "blur" },
        ],
      },
      row: {},
      rules1: {
        interviewTime: [
          { required: true, message: "面试不能为空", trigger: "blur" },
        ],
        arrivalTime: [
          { required: true, message: "到面不能为空", trigger: "blur" },
        ],
        offerTime: [
          { required: true, message: "预计入职不能为空", trigger: "blur" },
        ],
        isSend: [{ required: true, message: "短信不能为空", trigger: "blur" }],
      },
      operate: "约面",
      statusTwo: "2",
      statusThree: "",
      statusList: [],

      isTime1: false,
      isTime2: false,
      isTime3: false,
      index: "",
      childrenStatusList: [],
      count: {},
      wdqdList: [],
      qdkbId: null,
      pmId: null,
      tlId: null,
      qdkbData: {},
      ygrecordList: [],
    };
  },
  async created() {
    let res = await getWdqd(this.$route.query.orderId);
    this.wdqdList = [res.data];
    this.qdkbData = res.data;

    this.wdqdList.forEach((row) => {
      row.combinedInfo = {
        id: `ID:${row.qdkbId}`,
        employmentType: row.employmentType,
        positionName: row.positionName,
        brandName: row.brandName,
      };
    });
    this.qdkbId = res.data.qdkbId;
    this.pmId = res.data.enterUserId;
    this.tlId = res.data.userId;
    this.orderId = res.data.orderId;
    this.getList();
  },
  mounted() {
    this.childrenStatusList = staffStatus.find(
      (v) => v.value == this.queryParams.statusTwo
    ).children;
  },
  methods: {
    createaddSlmx(row) {
      let { qdkbId, ygId, name } = row;
      this.$modal
        .confirm('是否确认生成员工为"' + name + '"的数据项？')
        .then(function () {
          return addSlmx({ qdkbId, ygId });
        })
        .then(() => {
          this.$router.push("/systemtd/slmx");
        })
        .catch(() => {});
    },
    getListYgrecord(ygId) {
      listYgrecord({ ygId }).then((res) => {
        this.ygrecordList = res.rows;

        this.open3 = true;
      });
    },
    getListJl() {
      listJl().then((res) => {
        this.jlList = res;
        this.open = true;
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      this.queryParams.qdkbId = this.qdkbId;
      listYg(this.queryParams).then((response) => {
        this.count = {};
        response.countNumBos?.forEach((v) => {
          this.count[v.statusTwo] = v.num;
        });

        this.ygList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    changWay() {
      this.reset();
      this.jlId = null;
    },
    findJl() {
      let jl = this.jlList?.find((v) => v.jlId == this.jlId);
      let {
        jlId,
        educational,
        expectationCity,
        expectationJop,
        name,
        sex,
        tel,
        yearBirth,
      } = jl;
      this.form.name = name;
      this.form.sex = sex;
      this.form.expectationCity = expectationCity;
      this.form.expectationJop = expectationJop;
      this.form.educational = educational;
      this.form.yearBirth = yearBirth;
      this.form.tel = tel;
      this.form.jlId = jlId;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.open1 = false;
    },
    // 表单重置
    // 表单重置
    reset() {
      this.form = {
        jlId: null,
        name: null,
        tel: null,
        sex: "男",
        yearBirth: null,
        age: null,
        educational: null,
        expectationJop: null,
        expectationCity: null,
        createTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    listTab() {
      this.queryParams.statusThree = null;
      this.childrenStatusList = staffStatus.find(
        (v) => v.value == this.queryParams.statusTwo
      ).children;
      this.handleQuery();

      this.operate = this.statusTwoList[this.queryParams.statusTwo].operateName;
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.ygId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.way = 1;
      this.jlId = null;
      this.reset();

      this.title = "添加";
      this.getListJl();
    },
    async handleCommand(index, row) {
      this.index = index;
      if (index == 1) {
        let ygId = row.ygId;
        let statusOne = "2";
        let statusTwo = row.statusTwo;
        let statusThree = row.statusThree;
        let startStatusTwo = this.queryParams.statusTwo;
        this.$modal
          .confirm(`确认淘汰${row.name},编号为:${row.ygNo}的员工`)
          .then(function () {
            return updateYg({
              ygId,
              statusOne,
              statusTwo,
              startStatusTwo,
              statusThree,
              index,
            });
          })
          .then(() => {
            this.$modal.msgSuccess("淘汰成功");
            this.getList();
            this.listNum();
          })
          .catch(() => {});
      } else {
        this.handleUpdate(row);
      }
    },
    disabledDate(time) {
      // 获取当前时间并清除时分秒

      const currentDate = new Date();
      currentDate.setHours(0, 0, 0, 0);

      // 设置结束日期（2025-04-29的23:59:59）

      const endDate = new Date(this.interviewSendDate); // 注意月份从0开始（4月是3）

      endDate.setHours(23, 59, 59, 999);

      // 禁用条件：早于今天或晚于2025-04-29
      return (
        time.getTime() < currentDate.getTime() ||
        time.getTime() > endDate.getTime()
      );
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.row = {};
      const ygId = row.ygId;
      const statusTwo = this.queryParams.statusTwo;
      const ygStatus = ygId + "_" + statusTwo;
      getYg(ygStatus).then((response) => {
        this.row = response.data;
        const s = staffStatus.find((v) => v.value == this.row.statusTwo);
        this.statusList = s?.children;
        this.statusThree = this.row.statusThree;
        this.statusTwo = this.row.statusTwo;
        this.interviewSendDate = this.row.interviewSendDate;
        this.isTime1 = false;
        this.isTime2 = false;
        this.isTime3 = false;
        if (this.index == "3") {
          if (this.statusTwo == "1") {
            this.isTime1 = true;
          }
          if (this.statusTwo == "2") {
            this.isTime2 = true;
          }
          if (this.statusTwo == "3") {
            this.isTime3 = true;
          }
        }

        this.open1 = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.qdkbId = this.qdkbId;
          this.form.pmId = this.pmId;
          this.form.tlId = this.tlId;
          this.form.orderId = this.orderId;
          addYg(this.form).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    submitForm1() {
      this.$refs["row"].validate((valid) => {
        if (valid) {
          let data = { ...this.row };
          if (this.index == 3) {
            let statusTwo = parseInt(this.row.statusTwo) + 1;
            data.statusTwo = statusTwo;
            data.statusThree = statusTwoList[statusTwo].defaultStus;
          }
          data.index = this.index;
          data.startStatusTwo = this.queryParams.statusTwo;
          if (this.index == 3 && this.queryParams.statusTwo == 6) {
            this.$modal
              .confirm(
                "是否确认该员工离职，请确保离职前已经生成工单，否则有可能结算错误"
              )
              .then(function () {
                return updateYg(data);
              })
              .then(() => {
                this.getList();
                this.$modal.msgSuccess("成功");
                this.open1 = false;
              });
          } else {
            updateYg(data).then((response) => {
              this.getList();
              this.$modal.msgSuccess("成功");
              this.open1 = false;
            });
          }
        }
      });
    },
    listNum() {
      getWdqd(this.$route.query.orderId).then((res) => {
        this.wdqdList = [res.data];
        console.log(this.wdqdList, "====>");
        this.qdkbData = res.data;
        this.wdqdList.forEach((row) => {
          row.combinedInfo = {
            id: `ID:${row.qdkbId}`,
            employmentType: row.employmentType,
            positionName: row.positionName,
            brandName: row.brandName,
          };
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ygIds = row.ygId || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + ygIds + '"的数据项？')
        .then(function () {
          return delYg(ygIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport(flag) {
      if (flag) {
        this.queryParams.statusTwo = null;
      }
      this.download(
        "system/yg/export",
        {
          ...this.queryParams,
        },
        `人选管理_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
